<?php

class Application_Model_Filter_GetdataDump {

      /**
       *
       * 参数个数
       */
      public $countAttr;
      /**
       *
       * @var type 导出表名称
       */
      public $title;

      /**
       *
       * @var type 导出表列名
       */
      public $printHeadArr;

      /**
       *
       * @var 总清算
       */
      public $array;

      /**
       *
       * 赋值数组
       */
      public $printTypeArr;

      /**
       *
       * @var 导出数组
       */
      public $list;

      public function dumpDataTop() {
            error_reporting(NULL);
            ini_set('display_errors', 'Off');
            header("content-Type:text/html; charset=gb2312");
            header("Content-Type: application/vnd.ms-execl");
            header("Content-Disposition: attachment; filename=" . $this->title . ".csv");
            header("Pragma: no-cache");
            header("Expires: 0");
            if ($this->printHeadArr) {
                  foreach ($this->printHeadArr as $headVal) {
                        echo iconv("UTF-8", "GB2312", $headVal . ",");
                  }
                  echo "\r\n";
            }
            if ($this->array) {
                  foreach ($this->array as $arrayVal) {
                        echo iconv("UTF-8", "GB2312", $arrayVal . ",");
                  }
                  echo "\r\n";
            }
            return;
      }

      public function dumpArrayData($objlist) {
            foreach ($objlist as $value) {
                  foreach ($value as $result) {
                        echo $result . ",";
                  }
                  echo "\r\n";
            }
      }

      protected function getArr($Item, $value) {
            $array = $Item;
            if(in_array("function", $value)){
                  foreach ($value as $key => $result) {
                        if(!is_numeric($key)){
                              $money = $array->$key($result);
                              echo iconv("UTF-8", "GB2312", $money . ",");
                        }
                  }
            } 
//            else if(array_key_exists("object", $value)){
//                  $value = $value["object"];
//                  $temp = "";
////                  $cs = "";
//                  foreach ($value["valArr"] as $key => $result) {
////                        echo "<br>".$key."<br>".(count($value["valArr"])-1)."<br>";
////                        if($key == (count($value["valArr"])-1)){
////                              $cs .= $result;
////                        } else {
////                              $cs .= $result.",";
////                        }
//                        $temp[] = $result;
//                  }
////                  var_dump($temp);exit;
//                  $resultVal = $value["M"]::$value["F"](14318,202)->description  ;
//                  echo iconv("UTF-8", "GB2312", $resultVal . ",");
//            } 
            else {
                  foreach ($value as $result) {
                        $array = $array->$result;
                  }
                  echo iconv("UTF-8", "GB2312", $array . ",");
            }
      }

      public function dumpObjectData($objlist) {
            foreach ($objlist as $Item) {
                  foreach ($this->printTypeArr as $value) {
                        if (is_array($value)) {
                              $this->getArr($Item, $value);
                        } else {
                              $str = '';
                              if($value == 'txnId'){
                                $str = '悠奇';
                              }
                              echo iconv("UTF-8", "GB2312//IGNORE", $str.$Item->$value . ",");
                        }
                  }
                  echo "\r\n";
            }
      }
    public function dumoArrData($dataArr)
    {
        foreach ($dataArr as $dataKey => $dataVal) {
            if(is_array($dataVal)){
                echo iconv("UTF-8", "GB2312//IGNORE", $dataKey . ",");
                $this->getDataArr($dataVal);
            } else {
                echo iconv("UTF-8", "GB2312//IGNORE", $dataKey . ",");
                echo iconv("UTF-8", "GB2312//IGNORE", $dataVal . ",");
                echo "\r\n";
            }
        }
    }
    
    protected function getDataArr($dataArr)
    {
        foreach ($dataArr as $dataKey => $dataVal) {
            if(is_array($dataVal)){
                $this->getDataArr($dataVal);
                return;
            } else {
                echo iconv("UTF-8", "GB2312//IGNORE", $dataVal . ",");
            }
        }
        echo "\r\n";
    }
}
